from rest_framework import serializers
from admins.models import (
    Department,
    Position,
    RoleModel,
    AdminUserModel,
    ResourceModel,
    ResourceInterface,
    MutexModel
)

# 资源序列化器
class ResourceSerializer(serializers.ModelSerializer):

    class Meta:

        model = ResourceModel
        fields = [
            'id',
            'name',
            'url',
            'pid',
        ]

# 部门序列化器
class DepartmentSerializer(serializers.ModelSerializer):

    class Meta:
        model = Department
        fields = ['id', 'name']

# 职位序列化器
class PositionSerializer(serializers.ModelSerializer):

    class Meta:
        model = Position
        fields = ['id', 'name']

# 角色序列化器
class RoleSerializer(serializers.ModelSerializer):

    class Meta:

        model = RoleModel
        fields = [
            'id',
            'name',
            'pid',
            'resources',
            'type',
        ]

# 用户序列化器
class AdminUserSerializer(serializers.ModelSerializer):

    class Meta:

        model = AdminUserModel
        fields = [
            'id',
            'name',
            'role',
            'phone',
            'password',
        ]

class ResourceInterfaceSerializer(serializers.ModelSerializer):

    class Meta:

        model = ResourceInterface
        fields = [
            'id',
            'name',
            'url',
            'resid',
        ]

class MutexSerializer(serializers.ModelSerializer):

    class Meta:

        model = MutexModel
        fields = ['id', 'resource1', 'resource2']
